package cn.walls1717.ggkt.vod.controller;


import cn.walls1717.ggkt.model.vod.Teacher;
import cn.walls1717.ggkt.result.Result;
import cn.walls1717.ggkt.vo.vod.TeacherQueryVo;
import cn.walls1717.ggkt.vod.service.TeacherService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 讲师相关接口
 *
 * @author walls1717
 * @since 2022/06/29
 */
@Api(tags = "讲师相关接口")
@RestController
@RequestMapping("/admin/vod/teacher")
public class TeacherController {

    @Autowired
    private TeacherService teacherService;

    @ApiOperation("条件分页查询")
    @PostMapping("page/{pageNum}/{pageSize}")
    public Result<Page<Teacher>> listPages(@PathVariable Integer pageNum,
                                           @PathVariable Integer pageSize,
                                           @RequestBody(required = false) TeacherQueryVo teacherQueryVo) {
        Page<Teacher> pageInfo = teacherService.listPages(pageNum, pageSize, teacherQueryVo);
        return Result.success(pageInfo);
    }

    @ApiOperation("查询所有讲师")
    @GetMapping("findAll")
    public Result<List<Teacher>> listTeachers() {
        return Result.success(teacherService.list());
    }

    @ApiOperation("添加讲师")
    @PostMapping("save")
    public Result<?> saveTeacher(@RequestBody Teacher teacher) {
        teacherService.save(teacher);
        return Result.success();
    }

    @ApiOperation("根据id查询讲师")
    @GetMapping("{id}")
    public Result<Teacher> getTeacherById(@PathVariable Long id) {
        Teacher teacher = teacherService.getById(id);
        return Result.success(teacher);
    }

    @ApiOperation("修改讲师")
    @PostMapping("update")
    public Result<?> updateTeacher(@RequestBody Teacher teacher) {
        teacherService.updateById(teacher);
        return Result.success();
    }

    @ApiOperation("删除讲师")
    @DeleteMapping("remove/{id}")
    public Result<Boolean> deleteTeacherById(@PathVariable Long id) {
        teacherService.removeById(id);
        return Result.success();
    }

    @ApiOperation("批量删除讲师")
    @DeleteMapping("removeBatch")
    public Result<Boolean> deleteTeachers(@RequestBody List<Long> ids) {
        teacherService.removeByIds(ids);
        return Result.success();
    }

    @ApiOperation("根据id查询讲师(远程调用接口)")
    @GetMapping("inner/getTeacher/{id}")
    public Teacher innerGetTeacherById(@PathVariable Long id) {
        return teacherService.getById(id);
    }
}

